tmap <- function(v){
  aopt <- Tv <- v
  for (i in 1:length(v)) {
    # browser()
    rlt <- nlm(bellman_sg, k0[i], fscale = -1,
                 a0 = k0[i], agrid = k0, vold = v,
                 thetax = thetax, deltax = deltax, betax = betax, A = A)
    Tv[i] <- rlt$estimate
    aopt[i] <- rlt$minimum
  }
  return(list(v = Tv, aopt = aopt))
}
